/*
 * This file is part of TradeHelper library.
 *
 * TradeHelper library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TradeHelper library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TradeHelper library.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.rag.core;

import com.thoughtworks.xstream.annotations.XStreamAlias;

import java.util.HashMap;
import java.util.Map;

/**
 * User: mgarin Date: 04.04.12 Time: 16:42
 */

@XStreamAlias( "ItemType" )
public enum ItemType
{
    healingItem,
    usableItem,
    miscellaneous,
    weapon,
    armor,
    card,
    monsterEgg,
    petArmor,
    ammunition,
    delayedConsumable,
    tamingItem,
    throwWeapon,
    cashShopItem;

    private static transient Map<ItemType, String> typeNames = new HashMap<ItemType, String> ();

    static
    {
        typeNames.put ( healingItem, "Healing Item" );
        typeNames.put ( usableItem, "Usable Item" );
        typeNames.put ( weapon, "Weapon" );
        typeNames.put ( armor, "Armor" );
        typeNames.put ( card, "Card" );
        typeNames.put ( monsterEgg, "Monster Egg" );
        typeNames.put ( petArmor, "Pet Armor" );
        typeNames.put ( ammunition, "Ammunition" );
        typeNames.put ( delayedConsumable, "Delayed-Consumable" );
        typeNames.put ( tamingItem, "Taming Item" );
        typeNames.put ( throwWeapon, "Throw Weapon" );
        typeNames.put ( cashShopItem, "Cash Shop Item" );
        typeNames.put ( miscellaneous, "Miscellaneous" );
    }

    public String getTypeName ()
    {
        return typeNames.get ( this );
    }

    public static ItemType getItemType ( String typeName )
    {
        typeName = typeName.trim ();
        for ( ItemType key : typeNames.keySet () )
        {
            if ( typeNames.get ( key ).equals ( typeName ) )
            {
                return key;
            }
        }
        return ItemType.miscellaneous;
    }
}
